package com.fjh.controller;

import com.fjh.pojo.Activity;
        import com.fjh.service.ActivityService;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.web.bind.annotation.*;

        import java.util.List;
@RestController
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @PostMapping
    public Activity createActivity(@RequestBody Activity activity) {
        return activityService.createActivity(activity);
    }

    @PutMapping
    public Activity updateActivity(@RequestBody Activity activity) {
        return activityService.updateActivity(activity);
    }

    @PostMapping("/{activityId}/publish")
    public void publishActivity(@PathVariable Long activityId) {
        activityService.publishActivity(activityId);
    }

    @GetMapping
    public List<Activity> getAllActivities() {
        return activityService.getAllActivities();
    }
    @GetMapping("/search")
    public List<Activity> searchActivities(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status
    ) {
        return activityService.searchActivities(name, status);
    }



    @GetMapping("/{activityId}")
    public Activity getActivityById(@PathVariable Long activityId) {
        return activityService.findActivityById(activityId);
    }
}
